#购物车序列化器
from rest_framework.fields import SerializerMethodField
from rest_framework.serializers import ModelSerializer

from cart.models import CartModel


class CartSer(ModelSerializer):
    booklist=SerializerMethodField(read_only=True)
    def  get_booklist(self,obj):
        return {"name":obj.bookid.bookname,"price":obj.bookid.price,"count":obj.count,'img':obj.bookid.img}
    class Meta:
        model=CartModel
        fields='__all__'